-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
improved error message for invalid chart types #9417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -2262,11 +2262,13 @@ def result(self): | |||
|
|||
def _plot(data, x=None, y=None, subplots=False, | |||
ax=None, kind='line', **kwds): | |||
|
|||
invalid_ct_fmtstr = "'%s' is not a valid chart type" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use the word kind
instead of type
to match the keyword argument.
Also, perhaps use %r
instead of '%s'
to properly format non-string arguments, too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you formulate the message? 'blabla' is not a valid value for the keyword argument 'kind'
?
Is it possible to replace chart type
by chart kind
? I am not a native speaker - to me it somehow sounds strange.
at this point kind
can only be a string. It gets set in line 2265: kind = _get_standard_kind(kind.lower().strip())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "%r is not a valid plot kind"
? I see you are correct about the type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... I don't really have a strong opinion here about the exact wording.
In any case this is a clear improvement over the original. If you're happy with the wording that's fine.
@@ -2274,7 +2276,7 @@ def _plot(data, x=None, y=None, subplots=False, | |||
plot_obj = klass(data, x=x, y=y, subplots=subplots, ax=ax, | |||
kind=kind, **kwds) | |||
else: | |||
raise ValueError('Invalid chart type given %s' % kind) | |||
raise ValueError(invalid_ct_fmtstr % kind) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should ideally differentiate between the two messages. As the first message is just general 'not a valid plot kind'. While this message is specific for DataFrames (you get here if you give a kind that is only possible for a dataframe, but if your object is not a dataframe). So here I would say something like '%r is only a valid plot kind for DataFrames' or the like.
Can you check the new error messages? If they're ok, I would squash my commits. |
This looks good to me. @jorisvandenbossche ? |
kind = _get_standard_kind(kind.lower().strip()) | ||
if kind in _all_kinds: | ||
klass = _plot_klass[kind] | ||
else: | ||
raise ValueError('Invalid chart type given %s' % kind) | ||
raise ValueError("%r is not a valid plot kind" % kind) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a very small thing, but can you add '
around the %r
? I think that makes the message more clear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%r
seems to add the '
automatically: print("%r" % "hi")
prints: 'hi'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I didn't know that. Perfect then!
@cel4 Just a small question, can you squash the two commits into one? |
@cel4 Looking good, thanks! I'll merge when travis is green |
improved error message for invalid chart types
Closes #9400
pd.Series([2,3,4]).plot("quiver")
now gives an improved error message:instead of: